﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Dynamics.BusinessConnectorNet;
using System.Collections;


namespace PJ.Data.Inventory
{
    public class InventoryBarCodeAXProvider : EntityAXProvider<IInventoryBarCodeData>, IInventoryBarCodeProvider
    {
        public InventoryBarCodeAXProvider(IInventoryBarCodeCache<IInventoryBarCodeData> cache)
            : base(cache)
        {

        }

        public override IInventoryBarCodeData CreateNewItem()
        {
            return new BaseInventoryBarCodeData();
        }



        public string[] GetFragments(string ownerId, GetDataMode mode)
        {
            return EntityFragmentAXProvider.GetFragments(this.GetType(), (IEntityFragmentCache)Cache, ownerId, mode);
        }

        protected override void CopyFromContainer(IEnumerator enumerator, IInventoryBarCodeData data)
        {
            base.CopyFromContainer(enumerator, data);
            EntityFragmentAXProvider.CopyFromContainer(enumerator, data);
            if (enumerator.MoveNext())
            {
                data.Quantity = (double)enumerator.Current;
                if (enumerator.MoveNext())
                {
                    data.UnitId = ((string)enumerator.Current).Trim();
                    return;
                }
            }
            else
                throw new ArgumentException("Container size error", "enumerator");
        }

    }
}
